﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using ProjetoDLL.Model;
using ProjetoDLL.DAO;
using ProjetoDLL.BLL;

namespace ProjetoWebsite
{
    public partial class Login : System.Web.UI.Page
    {
        private Usuario usuario;
        private static String email = "";
        private static String senha = "";


        protected void Page_Load(object sender, EventArgs e)
        {
            lblAviso.Visible = false;
        }

        protected void btnLogIn_Click(object sender, EventArgs e)
        { 

            email = txtEmail.Text;
            senha = txtSenha.Text;
            usuario = OperacoesUsuario.autenticar(email, senha);

            //if (usuario != null && senha == usuario.Senha && usuario.Status.ToUpper() == "A")
            if (usuario != null)
            {
                lblAviso.Visible = false;
                Session["usuario"] = usuario.Nome;
                Session["email"] = usuario.Email;
                Session["senha"] = senha;
                FormsAuthentication.RedirectFromLoginPage(email, true);
            }
            else
            {
                lblAviso.Visible = true;
            } 
             
        }
    }
}